import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

public class Test {

    public static void main(String[] args){
        ReentrantLock lock = new ReentrantLock();

//        lock.lock();//中断线程不会抛出异常

//        try {
//            lock.lockInterruptibly();//中断线程会抛出异常
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

        try {
            lock.tryLock(5, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        //解锁
        lock.unlock();

        Semaphore semaphore = new Semaphore(2);
        try {
            semaphore.acquire(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        semaphore.acquireUninterruptibly(2);
        semaphore.release(2);
    }
}
